<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>06-VueRouter基础</title>
</head>
<body>
  <div id="app">
    <h1>Hello Vue Router!</h1>
    <p>
      <router-link to='/foo'>展示foo</router-link>
      <router-link to='/bar'>展示bar</router-link>
    </p>
    <router-view></router-view>
  </div>
</body>
<!-- <script src="./vue1111.js"></script>
<script src="./vue-router.js"></script> -->
<!-- 引入vue -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 引入VueRouter -->
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script>
  Vue.component('foo',{
    template:`<h2> 你好,这里是foo组件 </h2>`
  });
  var bar = {
    template:`<h2> 你好,这里是bar组件 </h2>`,
    computed: {
      getUserName(){
        return this.$route.parmas.username;
        
      }
    },
    methods:{
      goBack(){
        window.history.lenght > 1 ? this.$router.go(-1) : this.$router.push('/');
      }
    }
  };
  
  //具体路由匹配规则
  var routes =[
    {path:'/', component:'foo'},
    {path:'/foo', component:'foo'},
    {path:'/bar', component:bar},
  ];

  // 创建具体路由对象
  var router = new VueRouter({
      routes
  });

  var app = new Vue({
    el:'#app',
    //路由对象配置给vue实例
    router
  })
</script>
</html>